<?php
/**
 *       _____
 *      /  \  \      _       _    _____________   ___     ___ '  TM
 *     / /\ \  \    | |\    | |\ /_____   _____\ | - |   | - |
 *    / /  \ \  \   | | |   | | ||____/| |\____| | - |___| - |
 *   / /   /\ \  \  | | |   | | |    | | | |     | -  ___  - |
 *  / /   /  \ \  \ | |_|___| | |    | |_| |     | - |   | - |
 * / /___/    \ \__\|________ |/     |/___\|     |___|   |___|
 *________________________________________________________________________

 * Short description for file
 *
 * PHP version 5
 *
 * LICENSE: GNU General Public License v3
 *
 * @category
 * @package    Security
 * @author     Charly Poly <CharlyPoly@gmail.com>
 * @copyright  2009 Authentic Development Group
 * @license    GNU General Public License v3
 * @since      File available since Release 0.1.0
 */

class captcha {
    public function __construct() {

    }

    public static function display($md5) {
        header('Content-type: image/png');

        $im = imagecreatetruecolor(250, 70);

        $white = imagecolorallocate($im, 255, 255, 255);
        imagefilledrectangle($im, 0, 0, 249, 69, $white);

        /* Chargement d'une Font au hasard parmis 4 ! */
        $fonts = array('Monomadness.ttf', 'vtks_distress.ttf', 'sawesome.ttf','Karate.ttf');
        $font = dirname(__FILE__).DIRECTORY_SEPARATOR.'C_TTF'.DIRECTORY_SEPARATOR.$fonts[mt_rand(0,3)];

        /* Ajouter des barres pour gener les robots */
        for ($i=0; $i<20; $i++) {
            $r1 = mt_rand(0,255);
            $style = array($r1, $r1, $r1, $r1);
            imagesetstyle($im, $style);
            imageline($im, mt_rand(0,250), mt_rand(0,5)*microtime(), mt_rand(0,250), mt_rand(0,50), IMG_COLOR_STYLED);
        }

        // Création des lettres ..
        for ($i =0;$i<6;$i++) {
            $color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255));
            imagettftext($im, 40, mt_rand(0, 25), $i*30+mt_rand(10,20), mt_rand(45,60), $color, $font, $md5{$i});
        }



        imagepng($im);
        imagedestroy($im);
    }
}
?>
